<?php
$path = 'includes/admin/editors/fckeditor/editor/plugins/lemurcmslinks/';

function windowsToUnixPath ($str) {
	$str = preg_replace('/[a-zA-Z]:\\\/', '\\', $str);
	$str = str_replace("\\",'/', $str);
	return $str;
}

// Pages to split at to find the absolute server path directory
$basePages = array('dialog.php');
$base_url[0] = getcwd().'/';
foreach ($basePages as $value) {
	$base_url = explode($value, $base_url[0]);
}
$tbase = explode($path, windowsToUnixPath($base_url[0]));
define("T_BASE_URL", $tbase[0]);

$base_url2 = explode($path, windowsToUnixPath($_SERVER["REQUEST_URI"]));
define("S_BASE_URL", $base_url2[0]);

	require_once(T_BASE_URL.'config.php');
	require_once(T_BASE_URL.'includes/core.cleaning.functions.php');
	if(DB_USE == 'mysql')
		require_once(T_BASE_URL.'includes/db/mysql.core.class.php');
	elseif(DB_USE == 'sqlite')
		require_once(T_BASE_URL.'includes/db/sqlite.core.class.php');
	else
		die('no db configuration found');
	require_once(T_BASE_URL.'includes/core.functions.class.php');
	require_once(T_BASE_URL.'includes/core.theme.manger.class.php');
	require_once(T_BASE_URL.'includes/admin/core.admin.class.php');
	$admin = new admin;
	$theme = new themeManager;
	$admin->validate(ROOT_URL.'admin.php?login=true', '');
	$list = $theme->buildNavArray();
	$secondary_list = $theme->arraySecondaryNavigation();
	$main = $theme->optionListFromArray($list, "", "", 0, true, 1);
	$seco = $theme->optionListFromArray($secondary_list, "", "", 0, true, 1);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert Link</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link type="text/css" rel="stylesheet" href="<?php echo S_BASE_URL ?>includes/admin/editors/fckeditor/editor/skins/default/fck_dialog.css" />
		<script type="text/javascript" src="<?php echo S_BASE_URL ?>includes/admin/js/jquery-1.3.1.min.js"></script>
		<script src="<?php echo S_BASE_URL ?>includes/admin/editors/fckeditor/editor/dialog/common/fck_dialog_common.js" type="text/javascript"></script>
		<script type="text/javascript" src="fck_link.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {
				$('#txtUrl').val($('#menu').val());
				$('#menu').change(function () {
					$('#txtUrl').val($('#menu').val());
				});
				/*$('#submitLink').click(function() {
					Ok();
				});*/
			});
		</script>
	</head>
	<body>
		<select id="menu">
			<optgroup label="Main Menu">
				<?php echo $main ?>
			</optgroup>
			<optgroup label="Secondary Optional Menu">
				<?php echo $seco ?>
			</optgroup>
		</select>
		<!--<button id="submitLink">Insert a Link to this page!</button>-->
		<input id="txtUrl" value='' type="hidden"/>
	</body>
</html>